{include file="admin@public/header"/}

<style>
	.gridArea {
		padding: 7px 14px 0 14px;
	}

	.gridArea .btns {
		padding: 0 0 7px 0;
	}

	.gridArea .btns .ui-btn {
		margin-right: 0;
	}

	.ui-jqgrid-bdiv tr.ui-state-highlight {
		background: #f8ff94
	}

	#grid_operating {
		border-right-color: #D8DCE5;
	}

	td[aria-describedby=grid_operating],
	td[aria-describedby=accountGrid_operating] {
		border-right-color: #D8DCE5 !important;
	}

	.operating {
		display: inline;
		position: static;
		background: none;
		height: 16px;
	}

	.operating .ui-icon {
		height: 16px;
		line-height: 16px;
	}

	#query-pannel li {
		height: 30px;
		line-height: 30px;
	}

	#query-pannel .btns {
		position: absolute;
		top: 10px;
		right: 80px;
	}
	.mod-choose-input{position: relative;}
</style>


<div class="bill-ser-top">
	<ul class="ul-inline fix" id="filterItems">
		<li id="filter-billDate">
			<label>开票日期</label>
			<input type="date" value="" class="ui-input" name="filter-billFromDate" id="startdate"
				maxlength="10" style="width: 130px;">
			<span class="todate"> 至 </span>
			<input type="date" value="" class="ui-input" name="filter-billToDate" id="enddate" maxlength="10"
				style="width: 130px;">
		</li>
		<li id="date">
			<label>单据日期</label>
			<input type="date" value="" class="ui-input" name="filter-fromDate" id="dj_startdate" maxlength="10"
				style="width: 130px;">
			<span class="todate"> 至 </span>
			<input type="date" value="" class="ui-input" name="filter-toDate" id="dj_enddate" maxlength="10"
				style="width: 130px;">
		</li>
		<li id="billsNo">
			<label>单据编号</label>
			<input type="text" class="ui-input" id="gl_sn">
		</li>
		<!-- 选择供应商 -->
		{include file="admin@select/supplier"/}
		<li id="bill_no">
			<label>发票号</label>
			<input type="text" class="ui-input" id="invoice_no">
		</li>
		<li id="bill_title">
			<label>发票抬头</label>
			<input type="text" class="ui-input" id="invoice_title">
		</li>
		<li>
			<a class="ui-btn mrb ui-btn-search" id="search">查询</a>
		</li>
	</ul>
</div>
<!-- 功能区 -->
<div class="gridArea">
	<!-- 辅助功能 -->
	<div class="cf btns">
		<div class="fr">
			<a href="#" class="ui-btn-bill ui-btn-hl btn-sm fl mr10" id="export">导出</a>
			<a href="#" class="ui-btn-bill ui-btn-hl btn-sm fl" id="billDelete">删除</a>
		</div>
	</div>
	<!-- 数据列表 -->
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>

<script type="text/javascript">
	$(document).ready(function () {
		// 获取当前日期
		var myDate = new Date;
		var year = myDate.getFullYear(); //获取当前年
		var mon = myDate.getMonth() + 1; //获取当前月
		var date = myDate.getDate(); //获取当前日
		console.log(year + '-' + mon + '-' + date)
		if (mon < 10) {
			mon = "0" + mon;
		}
		if (date < 10) {
			date = "0" + date;
		}
		$("#startdate,#dj_startdate").val(year + '-' + mon + '-01');
		$("#enddate,#dj_enddate").val(year + '-' + mon + '-' + date);
	})
</script>
<script type="text/javascript">
	//$action_type 0 查询 1 导出
	function grid_search_list($action_type){
		   $("div.grid-subtitle").text("日期: " + startdate + " 至 " + enddate);
	       var startdate = $('#startdate').val();//
	       var enddate = $('#enddate').val();
	       var dj_startdate = $('#dj_startdate').val();//
	       var dj_enddate = $('#dj_enddate').val();
	       var gl_sn = $("#gl_sn").val();//单据编号
	       var invoice_no = $("#invoice_no").val();//发票号
	       var invoice_title = $("#invoice_title").val();//发票抬头
	       var supplier_id = $("#supplier_id").val();//供应商id


			if ($action_type==0) {
				var param={ 'ajax': '100', 'startdate': startdate, 'enddate': enddate, 'dj_startdate': dj_startdate,'dj_enddate':dj_enddate,'invoice_no':invoice_no,'invoice_title':invoice_title,'gl_sn':gl_sn,'user_id':supplier_id}; //发送数据   
			}else if($action_type==1){
				var param={ 'is_export':1,'ajax': '100', 'startdate': startdate, 'enddate': enddate, 'dj_startdate': dj_startdate,'dj_enddate':dj_enddate,'invoice_no':invoice_no,'invoice_title':invoice_title,'gl_sn':gl_sn,'user_id':supplier_id};
				var export_param='';
				for(let key  in param){
					export_param+=key+'='+ param[key]+'&';
				}
				export_param = export_param.substr(0, export_param.length - 1);  
				//console.log(export_param);
				window.location.href="index.html?"+export_param;
				return false;
			}
			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: param, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
	}
</script>
<script type="text/javascript">
	$(document).ready(function () {
		 // 选择删除
	    $("#billDelete").click(function () {
	    	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
	      	if (ids == '' || ids == null) {
				layer.msg('请先选择需要删除的项！');
				return false;
			}
			//获取商品信息
			$.post('del.html', { id: ids, status: 0,type:2 }, function (res) {
				layer.msg(res.msg);
				if (res.status == 1) {
					reload();
				}
			});
	    })

	    // 导出按钮
		$("#export").click(function () {
			grid_search_list(1);//0 查询 1 导出
		});

		// 点击查询按钮
		$("#search").click(function () {
			grid_search_list(0);//0 查询 1 导出
		});
		
    })
</script>
<script type="text/javascript">
	//$(function(){
	$(document).ready(function () {

		// 跳转打开新标签页
		$(".ta").click(function () {
			var tabid = $(this).attr('tabid');
			var tabTxt = $(this).attr('tabTxt');
			var _href = $(this).attr('_href');
			parent.tab.addTabItem({
				tabid: tabid,
				text: tabTxt,
				url: _href
			})
		})

		// 鼠标移入订单状态
		$("#filter-menu").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		})
		// 按钮移入移出
		$(".ui-btn-menu.ml10").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		})

		//alert("1111");
		$("#grid").jqGrid({
			url: '/scm/purchasebilling/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["操作", "单据日期", "单据编号", "供应商", "金额", "税额", "价税合计", "付款状态", "开票日期", "开票金额", "发票号", "发票抬头",'o_type'],
			colModel: [
				{ name: 'id', index: 'id', width: 70, formatter: actions, align: "center" },
				{ name: 'gl_dj_time', width: 90 },
				{ name: 'gl_sn', width: 120, },
				{ name: 'gl_c_name', width: 100, },
				{ name: 'gl_jine', width: 90 ,align:"right" },
				{ name: 'gl_tax_e_sum', width: 90 ,align:"right" },
				{ name: 'gl_total_price_sum', width: 90 ,align:"right" },
				{ name: 'pay_status_name', width: 80 },
				{ name: 'dj_time', width: 90 },
				{ name: 'invoice_price', width: 100 ,align:"right" },
				{ name: 'invoice_no', width: 200 },
				{ name: 'invoice_title', width: 200 },
				{ name: 'o_type', hidden:true }
			],
			sortable: true,  //排序

			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			multiselect:true, //自带复选框
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			// 合计
			footerrow: true,
			gridComplete: function () {
				var after_discounts = parseFloat($("#grid").getCol('after_discount', false, 'sum')).toFixed(2);
				var tax_prices = parseFloat($("#grid").getCol('tax_price', false, 'sum')).toFixed(2);
				var sum_price_taxs = parseFloat($("#grid").getCol('sum_price_tax', false, 'sum')).toFixed(2);
				var invoice_prices = parseFloat($("#grid").getCol('invoice_price', false, 'sum')).toFixed(2);
				$("#grid").footerData('set', { "invpu_addtime": '合计：', after_discount: after_discounts, tax_price: tax_prices ,sum_price_tax:sum_price_taxs ,invoice_price:invoice_prices});

				var grid = $("#grid");
       
		        var ids = grid.getDataIDs();
		        var rowDatas = grid.jqGrid("getRowData");//获取所有行的数据
		        //alert(col_hs);
		        for (var i = 0; i < ids.length; i++) {
		          var rowData = rowDatas[i];
		          if (rowData.o_type == "5") {
		            $("#" + ids[i] + " td").css("color", "#ff0000");
		          }
		        }
			}
		});
	});


	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')">删除</span></div>';
	}

	

</script>

{include file="admin@public/footer"/}